import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class cartoon_view_record extends StatefulWidget {
  const cartoon_view_record({Key key}) : super(key: key);

  @override
  State<cartoon_view_record> createState() => _cartoon_view_recordState();
}

class _cartoon_view_recordState extends State<cartoon_view_record> {
  List cartoon_list0 = [
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '间谍过家家',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
    {
      'cartoon': 0,
      'imageUrl':
          'https://nianyiman-1309342317.cos-website.ap-guangzhou.myqcloud.com/jdgjj/jdgjj0.png',
      'name': '姓名',
      'data': '2019-10-14 10:6:12.278',
      'read': 12,
      'allnum': 32,
    },
  ];
  ScrollController _scrollController = new ScrollController();
  Future _future;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _future = _getinformation();
    _scrollController.addListener(() {
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent) {
        // _onLoadmore();
        print('滑到了最底部');

        setState(() {});
      }

      // print('滑了');
    });
  }

  _getinformation() async {
    print('加载');
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
        future: _future,
        builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            return RefreshIndicator(
              onRefresh: () async {
                //模拟网络请求
                setState(() {
                  // rank_num = 0;
                });
                print('上拉刷新');
                await Future.delayed(Duration(milliseconds: 2000));
                //结束刷新
                return Future.value(true);
              },
              child: ListView(
                controller: _scrollController,
                children: cartoon_list0
                    .asMap()
                    .keys
                    .map((e) => Container(
                          margin: EdgeInsets.only(
                              top: 10, bottom: 10, left: 20, right: 20),
                          height: 100,
                          // color: Colors.red,
                          child: Row(
                            children: [
                              Container(
                                child: Image(
                                  height: 100,
                                  width: 75,
                                  fit: BoxFit.fill,
                                  image: NetworkImage(
                                      cartoon_list0[e]['imageUrl']),
                                ),
                              ),
                              Column(
                                children: [
                                  Container(
                                    width: 160,
                                    // color: Colors.green,
                                    alignment: Alignment.centerLeft,
                                    margin: EdgeInsets.only(top: 8, left: 10),
                                    child: Text(cartoon_list0[e]['name']),
                                  ),
                                  Container(
                                    width: 160,
                                    margin: EdgeInsets.only(top: 10, left: 4),
                                    child: Text(
                                      '看到' +
                                          cartoon_list0[e]['read'].toString() +
                                          '话/更新到' +
                                          cartoon_list0[e]['allnum']
                                              .toString() +
                                          '话',
                                      style: TextStyle(
                                          fontSize: 12, color: Colors.black54),
                                    ),
                                  ),
                                  Expanded(child: SizedBox()),
                                  Container(
                                    child: Text(cartoon_list0[e]['data']),
                                  )
                                ],
                              ),
                              Expanded(child: SizedBox()),
                              InkWell(
                                onTap: () {
                                  print('续看');
                                },
                                child: Container(
                                  width: 60,
                                  height: 30,
                                  alignment: Alignment.center,
                                  decoration: new BoxDecoration(
                                    // color: Colors.red,
                                    // 设置四周圆角，角度
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(50.0)),
                                    border: new Border.all(
                                        color: Color.fromRGBO(1, 174, 231, 1),
                                        width: 0.5),
                                  ),
                                  child: Text(
                                    '续看',
                                    style: TextStyle(
                                      color: Color.fromRGBO(1, 174, 231, 1),
                                    ),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ))
                    .toList(),
              ),
            );
          } else
            return Container();
        });
  }
}
